// 实现new 关键字
/*
实现要点：
new 会产生一个新对象；
新对象需要能够访问到构造函数的属性，所以需要重新指定它的原型；
构造函数可能会显示返回；
*/

const objectFactory = function (Constructor: any, ...args: any[]) {
  // const [Constructor, ...args] = arguments as any;
  const obj: any = {};
  obj.__proto__ = Constructor.prototype;
  const ret = Constructor.apply(obj, args);
  return ret || obj;
};

class Person {
  name: any;
  age: any;
  constructor(name: any, age: any) {
    this.name = name;
    this.age = age;
  }

  get yuan() {
    return this.#yuan + 'cqc';
  }

  #yuan = '233';
}

const p = objectFactory(Person, 'cqc', 24);
console.log('instance', p);
p;

export {};
